<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="<%=basePath%>/js/jquery-1.9.0.js"></script>
<script type="text/javascript">
	$(function(){
		var href=window.location.href;
		var arrhref=href.split("?pramter=");
		var proAmount = arrhref[1];
		var proId = arrhref[2];
		var proLeft = arrhref[3];
		var userId="1";
		var amountLeft;
		//根据产品ID查询当前产品信息
		$.ajax({
	         type: "POST",
	         url:"<%=basePath%>invest/getProKinds?proId=" + proId,
			 dataType : 'JSON',
			 success : function(data) {
				 bindData(data);
			 }
		});
		//绑定页面信息
		function bindData(data){
			$.post("<%=basePath%>user/getById?userId=" + userId,function(result){
				amountLeft = result.amount_left;
				$("#amountLeft").val(result.amount_left);
			});
			alert("==");
			$("#elseDiv").hide();
			$("#proName").val(data.pro_name);
			$("#proPrice").val(proAmount);
			$("#payNum").val(proAmount);
			//判断当前账户余额是否大于支付金额
			if(parseFloat(amountLeft)>parseFloat(proAmount)){
				$("#checkAmount").attr("checked","checked");
				amountLeft = parseFloat(amountLeft) - parseFloat(proAmount);
			}else{
				$("#elsePay").focus();
			}
		}
		$("#elsePay").click(function(){
			$("#elseDiv").toggle();
			$("#elsePay").blur();
		});
		//立即支付按钮事件
		$("#pay").click(function(){
			$.ajax({
		         type: "POST",
		         url:"<%=basePath%>invest/payProduct",
		         data :  {"proId":proId,"id":userId,"proLeft":proLeft,"amountLeft":amountLeft,"amount":proAmount},
				 dataType : 'JSON',
				 success : function(result) {
					 if(result.success){
						 alert("支付成功");
						 window.location.reload(); 
					 }else{
						 alert("支付失败");
					 }
				 }
			});
		});
	});
</script>
<title>订单支付</title>
</head>
<body>
	<div>
		<table>
			<tr>
				<td>产品名称：</td>
				<td><input id="proName" disabled="true"></td>
				<td>订单总额：</td>
				<td colspan="2"><input id="proPrice" disabled="true"></td>
			</tr>
			<tr>
				<td><input id="checkAmount" name="payType" type="radio">账户余额：</td>
				<td><input id="amountLeft" disabled="true"></td>
				<td>支付：</td>
				<td><input id="payNum" disabled="true"></td>
			</tr>
			<tr>
				<td><input id="elsePay" type="button" value="其他付款方式" style="text-align:center"></td>
			</tr>
		</table>
	</div>
	<div id="elseDiv">
		<input id="payFY" name="payType" type="radio">
		<input disabled='true' value='富友支付'/>
	</div>
	<div>
		<input id="pay" type="button" value="立即支付"/>
		<input id="return" type="button" value="返回" onClick="history.back();"/>
	</div>
</body>
</html>